package com.service.affiliate.google;

import java.util.Arrays;
import java.util.List;

import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.oauth2.LocalServerReceiver;
import com.google.api.oauth2.OAuth2Native;
import com.google.api.services.gan.Gan;

public class GanServer 
{
	private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();

	/** Global instance of the JSON factory. */
	private static final JsonFactory JSON_FACTORY = new JacksonFactory();
	private List<String> scopes = Arrays.asList("https://www.googleapis.com/auth/gan");
	
	protected String publisherId = "K380716";
	
	protected String appName = "hohocoupon";
	protected String version = "v1";
	   
	protected Gan server;
	
	public void setPublisherId(String publisherId)
	{
		this.publisherId = publisherId;
	}

	public void setScopes(List<String> scopes)
	{
		this.scopes = scopes;
	}
	
	public void setUp() throws Exception
	{
	    HttpTransport httpTransport = new NetHttpTransport();
	    JacksonFactory jsonFactory = new JacksonFactory();	    

	    /**
	     * Make sure to update the client_secrets.json file or you will get an error.
	     * See the Java sample code for more information.
	     */
	    Credential credential;
	
		credential = OAuth2Native.authorize(httpTransport, jsonFactory, new LocalServerReceiver(), scopes);
		
		server = new Gan.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(appName + "/" + version).build();
	}
}
